import React, { Component } from 'react'
import PropTypes from 'prop-types'

export default class Item extends Component {
    static propTypes = {
        detail: PropTypes.object.isRequired,
        deleteItem: PropTypes.func.isRequired,
        changeStatus: PropTypes.func.isRequired
    }
    deleteItem = () => {
        const { id } = this.props.detail;
        this.props.deleteItem(id);
    }
    changeStatus = () => {
        const { id } = this.props.detail;
        this.props.changeStatus(id);
    }
    render() {
        const { title, done } = this.props.detail;
        return (
            <li><input type='checkbox' onChange={this.changeStatus} checked={done} /> {title}<button onClick={this.deleteItem}>删除</button></li>
        )
    }
}
